import time
import json
from django.utils.deprecation import MiddlewareMixin


class RequestLoggingMiddleware(MiddlewareMixin):
    def process_request(self, request):
        request.start_time = time.time()

    def process_response(self, request, response):
        if hasattr(request, 'start_time'):
            duration = time.time() - request.start_time
            log_data = {
                'method': request.method,
                'path': request.path,
                'params': dict(request.GET),
                'duration': f"{duration:.2f}s"
            }
            print(json.dumps(log_data))  # In a real-world scenario, you'd use proper logging
        return response
